Skip to main content
ICT
Lesson A10 - The String Class
 
Main Previous Next
Title Page >  
Summary >  
Lesson A1 >  
Lesson A2 >  
Lesson A3 >  
Lesson A4 >  
Lesson A5 >  
Lesson A6 >  
Lesson A7 >  
Lesson A8 >  
Lesson A9 >  
Lesson A10 >  
Lesson A11 >  
Lesson A12 >  
Lesson A13 >  
Lesson A14 >  
Lesson A15 >  
Lesson A16 >  
Lesson A17 >  
Lesson A18 >  
Lesson A19 >  
Lesson A20 >  
Lesson A21 >  
Lesson A22 >  
Lesson AB23 >  
Lesson AB24 >  
Lesson AB25 >  
Lesson AB26 >  
Lesson AB27 >  
Lesson AB28 >  
Lesson AB29 >  
Lesson AB30 >  
Lesson AB31 >  
Lesson AB32 >  
Lesson AB33 >  
Vocabulary >  
 

B. String Constructors page 4 of 17

  1. Because Strings are objects, you can create a String object by using the keyword new and a String constructor method, just as you would create any other object.

    String name = new String();
    String name2 = new String(“Nancy”);

  2. Though they are not primitive types, strings are so important and frequently used that Java provides additional syntax for declaration:

    String aGreeting = "Hello world";

    A String created in this short-cut way is called a String literal. Only Strings have a shortcut like this. All other objects are constructed by using the new operator.

    Many new Java programmers get confused because of this shortcut and believe that Strings are primitive data types. However, Strings are objects and therefore have behaviors and attributes.

 

Main Previous Next
Contact
 © ICT 2006, All Rights Reserved.